<?php

class Application_Form_User extends Zend_Form {

    public function init() {
        // Set the method for the display form to POST
        $this->setMethod('post');
        $this->setName('userform');

        // Add the comment element
        $this->addElement('text', 'username', array(
            'label' => 'Username:',
            'size' => 18,
            'maxlength' => 15,
            'required' => true,
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(4, 15))
            )
        ));


        // Add the comment element
        $this->addElement('password', 'password', array(
            'label' => 'Password:',
            'size' => 18,
            'maxlength' => 15,
            'required' => false,
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(6, 15))
            )
        ));

        // Add the comment element
        $this->addElement('text', 'real_name', array(
            'label' => 'Full name:',
            'size' => 50,
            'maxlength' => 255,
            'required' => true,
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(0, 255))
            )
        ));

        // Add the comment element
        $this->addElement('text', 'email', array(
            'label' => 'E-mail:',
            'size' => 30,
            'maxlength' => 255,
            'required' => false,
            'validators' => array(
                array('validator' => 'EmailAddress')
            )
        ));

        $role = new Zend_Form_Element_Select('role');
        $role->setLabel('Role')
                ->setRequired()
                ->addErrorMessage('Role required!');

        $role->addMultiOption('admin', 'Administrator');
        $role->addMultiOption('user', 'User');


        $this->addElement($role);


        // Add the submit button
        $this->addElement('submit', 'submit', array(
            'ignore' => true,
            'label' => 'Save',
        ));

        // And finally add some CSRF protection
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
        ));
    }

}

